(function (mui, window) {
    var v3DevMonitor = window.v3DevMonitor = {};
    var baseRequest = window.baseRequest;
    var appConfig = window.appConfig;
    var commonTool = window.commonTool;
    var dataManager = window.dataManager;
    var locale = dataManager.getLocale();

    //add by wuchengcheng
    //系统信息
    var getSystemInfoUrl = appConfig.v3ServiceUrl + '/devmonitor/app/system?';
    //获取场所信息
    v3DevMonitor.getSystemInfo = function (devSn, callback) {
        baseRequest.commonGet(getSystemInfoUrl + mui.param({
                devSN: devSn
            }), 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data == -1 || data.errcode) {
                    callback(1);
                } else {
                    callback(0, data);
                }
            }
        });
    }

    //  end

    //add by ding
    var getWanSpeedUrl = appConfig.v3ServiceUrl + '/devmonitor/app/wanspeed?';
    v3DevMonitor.getWanSpeed = function (devSN, callback) {
        baseRequest.commonGet(getWanSpeedUrl + mui.param({
                devSN: devSN
            }), 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                console.log(JSON.stringify(data));
                if (data == -1 || data.errcode) {
                    callback(1);
                } else {
                    callback(0, data);
                }
            }
        });
    }
    //end


    //add by zhangfuqiang
    var getWanInfoUrl = appConfig.v3ServiceUrl + '/devmonitor/app/waninfo?';
    /**
     * 获取WAN的信息
     * @param {String} devSN
     * @param {Object} callback
     */
    v3DevMonitor.getWanInfo = function (devSN, callback) {
        baseRequest.commonGet(getWanInfoUrl + $.param({devSN: devSN}), function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            callback(0, data.wan_list);
        });
    };

    var getUpLinkInterfaceDataUrl = appConfig.v3ServiceUrl + '/devmonitor/getUpLinkInterfaceData?';
    /**
     * 流量监控
     * @param devSN
     * @param interfaceType
     * @param callback
     */
    v3DevMonitor.getUpLinkInterfaceData = function (devSN, interfaceType, callback) {
        baseRequest.commonGet(getUpLinkInterfaceDataUrl + $.param({
                interfaceType: interfaceType,
                devSN: devSN
            }), function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, JSON.parse('[' + data.histdataList + ']'));
        })
    }
    
    var getSpeedInterfaceDataUrl = appConfig.v3ServiceUrl + '/devmonitor/setOneInterface?';
    /**
     * 各端口速度监控
     * @param devSN
     * @param interfaceName
     * @param interfaceType
     * @param callback
     */
    
	v3DevMonitor.getSpeedInterfaceData = function (devSN, interfaceType, interfaceName, callback) {
        baseRequest.commonGet(getSpeedInterfaceDataUrl + $.param({
                interfaceType: interfaceType,
                interfaceName: interfaceName,
                devSN: devSN
           }), function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data.histdataList);
        })
    }
	
	var getTotalSpeedDataUrl = appConfig.v3ServiceUrl + '/devmonitor/getAllInterfacesFlow?';
    /**
     * 总速度监控
     * @param devSN
     * @param interfaceName
     * @param interfaceType
     * @param callback
     */
    
	v3DevMonitor.getTotalSpeedData = function (devSN, callback) {
        baseRequest.commonGet(getTotalSpeedDataUrl + $.param({
                devSN: devSN
           }), function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data.DataList);
        })
    }
	
	var getAllInterfaceUrl = appConfig.v3ServiceUrl + '/devmonitor/getAllInterfaces?';
    /**
     * 获取所有端口信息
     * @param devSN
     * @param callback
     */
    v3DevMonitor.getAllInterfaces = function (devSN, callback) {
        baseRequest.commonGet(getAllInterfaceUrl + $.param({
                devSN: devSN
            }), function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data.InterfaceList);
        })
    }
    // end
    
    // by wangyu
    	 var getCpuinfo = appConfig.v3ServiceUrl + '/devmonitor/app/cpuinfo?';
    	 v3DevMonitor.getCpuinfo = function(devSN, callback){
    	 	baseRequest.commonGet(getCpuinfo + $.param({
    	 		devSN: devSN
    	 	}), 10000, function(code, data){
    	 		if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errCode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data);
    	 	})
    	 }
    	 
    	 var getMemoryinfo = appConfig.v3ServiceUrl + '/devmonitor/app/memoryinfo?';
    	 v3DevMonitor.getMemoryinfo = function(devSN, callback){
    	 	baseRequest.commonGet(getMemoryinfo + $.param({
    	 		devSN: devSN
    	 	}), 10000, function(code, data){
    	 		if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errCode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data);
    	 	})
    	 }
    	 
    	 var getDevspeed = appConfig.v3ServiceUrl + '/devmonitor/app/devspeed?';
    	 v3DevMonitor.getDevspeed = function(devSN, callback){
    	 	baseRequest.commonGet(getDevspeed + $.param({
    	 		devSN: devSN
    	 	}), 10000, function(code, data){
    	 		if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errCode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data);
    	 	})
    	 }
    
    var getCpuHistory = appConfig.v3ServiceUrl + '/devmonitor/gethistcpuratioinfoby10Min?';
    v3DevMonitor.getCpuHistory = function(devSN, startTime, endTime, callback){
    		baseRequest.commonGet(getCpuHistory + $.param({
    			devSN: devSN,
    			startTime: startTime,
    			endTime: endTime
    		}), function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data.dataList);
    		})
    }
    
    var getMemeryHistory = appConfig.v3ServiceUrl + '/devmonitor/gethistmemoryratioinfoby10Min?';
    v3DevMonitor.getMemeryHistory = function(devSN, startTime, endTime, callback){
    		baseRequest.commonGet(getMemeryHistory + $.param({
    			devSN: devSN,
    			startTime: startTime,
    			endTime: endTime
    		}), function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (data == -1 || data.errcode) {
                return callback(1, locale.base.err.request);
            }
            return callback(0, data.dataList);
    		})
    }
    
    //end
}(mui, window));